import * as Types from 'containers/ActionTypes';

export default function (state = {}, action) {
  var uploadsCount;
  switch (action.type) {
  case Types.MY.UPLOADS.UPDATE_MY_UPLOADS_COUNT:
    return Object.assign({}, state, {
      uploadsCount: action.totalCount,
    });
  case Types.MY.PUBLISH_SUCCESS:
    uploadsCount = state.uploadsCount;
    return Object.assign({}, state, {
      uploadsCount: uploadsCount - 1,
    });
  case Types.MY.UNPUBLISH_SUCCESS:
    uploadsCount = state.uploadsCount;
    return Object.assign({}, state, {
      uploadsCount: uploadsCount + 1,
    });
  case Types.MY.DELETE_SUCCESS:
    uploadsCount = state.uploadsCount;
    return action.status === 'PRIVATE'
      ? Object.assign({}, state, { uploadsCount: uploadsCount - 1 })
      : state;
  default:
    return state;
  }
}
